package com.qxzn.app.medicalhealth.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.qxzn.app.bean.ContactsBean;
import com.qxzn.app.bean.MedicineRecordImgBean;
import com.qxzn.app.medicalhealth.R;
import com.qxzn.app.medicalhealth.R2;

import java.io.File;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AddMedicalCaseImgAdapter extends RecyclerView.Adapter<AddMedicalCaseImgAdapter.ViewHolder> {

    private Activity activity;
    private List<MedicineRecordImgBean> dataList;
    private MedicineRecordImgBean item;
    private View.OnClickListener delClick;

    public AddMedicalCaseImgAdapter(Activity activity, List dataList) {
        this.activity = activity;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_add_medicine_case_img, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        item = dataList.get(position);
        if (position == 0) {
            holder.ivDelete.setVisibility(View.INVISIBLE);
            Glide.with(activity).load(R.mipmap.logo).apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.mipmap.logo).error(R.mipmap.logo)).into(holder.ivIcon);
        } else {
            holder.ivDelete.setVisibility(View.VISIBLE);
            holder.ivDelete.setTag(position);
            holder.ivDelete.setOnClickListener(delClick);
            Glide.with(activity).load(item.getObject()).apply(new RequestOptions().placeholder(R.mipmap.logo).error(R.mipmap.logo)).into(holder.ivIcon);
        }
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void setDelClick(View.OnClickListener delClick) {
        this.delClick = delClick;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.iv_icon)
        ImageView ivIcon;
        @BindView(R2.id.iv_delete)
        ImageView ivDelete;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
